// 创建user的store
import {defineStore} from "pinia";

export const useUserStore = defineStore('user', {
    state:()=>{
        return {
            userName:"",
            password:"",
            id:0
        }
    },
    getters:{
        getUserName: (state) => state.userName,
        getPassword: (state) => state.password,
        getId: (state) => state.id
    },
    actions:{
        setUserName(userName:string){
            this.userName = userName
        },
        setPassword(password:string){
            this.password = password
        },
        setId(id:number){
            this.id = id
        }
    },
    // 配置持久化
    persist: {
        enabled: true,// 开启该模块的持久化
        strategies: [
            {
                key: 'user',// 持久化的key
                storage: localStorage,
                paths: ['userName', 'id']
            }
        ]
    }
})